package com.aaa.stock.controller.prov;

import com.aaa.entity.Producer;
import com.aaa.entity.Provider;
import com.aaa.stock.service.prov.ProviderService;
import com.aaa.stock.vo.ProvdierVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/stock/prov/prov")
public class StockProvController {

    @Autowired
    private ProviderService providerService;

    @PostMapping("provList/{currentPage}/{pageSize}")
    public Result<IPage<Provider>> prodList(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody ProvdierVo producerVo
    ){
        return providerService.findByListtion(currentPage,pageSize,producerVo);
    }
    //删除
    @DeleteMapping("deleteProv/{providerIds}")
    public Result<Map<String,Object>> deleteProv(@PathVariable Long providerIds){
        return providerService.deleteProv(providerIds);
    }
    //添加
    @PostMapping("addProv")
    public Result addProv(@RequestBody Provider provider){
        providerService.saveOrUpdate(provider);
        return new Result(2000,"添加成功");
    }
    //批量删
    @PostMapping("delAll")
    public Result delAll(@RequestBody List<Provider> providers){
        providers.forEach((Provider prov)->{
            boolean b =providerService.removeById(prov.getProviderId());
        });
        return new Result(2000,"成功");
    }
    //查供应商
    @PostMapping("selectAllProvName")
    public Result<List<Provider>> selectAllProvName(){

        return providerService.selectAllProvName();
    }
}
